﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HA.Data;

namespace HA.ModFlow.Application
{
    public class BackImagesViewModel : MDTVIViewModel
    {
        public BackImagesViewModel(MDTVIViewModel parent,AssistData data):base(parent,false)
        {



            this._assistData = data;


            this._imageSource = VMImageSource.imageCollection;

            this._contextMenu = new System.Windows.Controls.ContextMenu();

            this.LoadChildren();

 
        }


        AssistData _assistData;

        public override string Desc
        {
            get
            {
                return "背景图(位图)";
            }
        }

        protected override void LoadChildren()
        {



            base.LoadChildren();

            ImageViewModel img;

            foreach (BitImageInfoes item in this._assistData.BitImageIdAndInfoes.Values)
	        {

                img = new ImageViewModel(this,item);

                this.Children.Add(img);
		 
	        }


            this._assistData.BitImageChanged += new EventHandler<BitImageCollectionChangedEventArgs>(_assistData_BitImageChanged);


        }

        void _assistData_BitImageChanged(object sender, BitImageCollectionChangedEventArgs e)
        {

            ImageViewModel img;

            switch (e.Type)
            {
                case CollectionChangedType.ADD:

                    foreach (BitImageInfoes item in e.ImageIdAndInfoes.Values)
	                {

                        img = new ImageViewModel(this,item);

                        this.Children.Add(img);
		 
	                }


                    break;
                case CollectionChangedType.REMOVE:

                    foreach (string item in e.DeleteImageIds)
	                {


                        img = (ImageViewModel)this.Children.FirstOrDefault<MDTVIViewModel>(h => (h as ImageViewModel).ImageInfo.Id == item);

                        this.Children.Remove(img);
		 
	                }

                    break;
                case CollectionChangedType.MOVE:
                    break;
                case CollectionChangedType.REPLACE:
                    break;
                case CollectionChangedType.ITEMEDIT:
                    break;
                case CollectionChangedType.RESET:
                    break;
                default:
                    break;
            }



            ProjectDataViewModel parent = (ProjectDataViewModel)this.Parent;

            parent.CollectionView.Refresh();


        }


    }
}
